package chixing.day03;

import java.util.Arrays;

public class MethodDemp {
    public static void main(String[] args) {
       int a[]={61,19,56,37,20 ,66,50,34,77,89};
        a= insertsort(a ,0,a.length-1);
       for (int i = 0; i < a.length; i++) {
           System.out.print(a[i]+" ");
       }
       Arrays.sort(a);
       int x = 0;
       x+=2;
    }
    public static int[] quick(int [] a,int low,int high){
        if(low<high){
            int middle=gitMiddle(a,low,high);
            quick(a,low,middle-1);
            quick(a,middle+1,high);
        }
        return a;
    }
    public static int [] quickSort(int[] a){
          if(a.length>=2)
              quick(a,0,a.length-1);
          return a;
    }
    public static int gitMiddle(int[] a,int low,int high) {
        int temp = a[low];
        while (low < high) {
            while (low < high && a[high] >= temp) {
                high--;
            }
            a[low] = a[high];
            while (low < high && a[low] <= temp) {
                low++;
            }
            a[high] = a[low];
        }
        a[low] = temp;
        return low;
    }
public static int[] insertsort(int[] a,int i,int j){
        for (int k = i+1; k < j; k++) {
            int temp = a[k];
            int j1 = k-1;
            for (; j1 >= i; j1--) {
                if(a[j1]>temp){
                    a[j1+1]=a[j1];
                }else{
                    break;
                }
            }
            a[j1+1]=temp;
        }
        return a;
}

}
